
import java.io.IOException;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author FFK
 */
public abstract class Menudetail {
    
    public Image normal;
    public Image highlighted;
    public boolean ishighlighted;
    public int posX;
    public int posY;
    public Menudetail(){
        
    }
    public abstract void setMenuItem();
    public void init(String nomarlimage , String highlightedimage){
        ImageLoader loader = ImageLoader.getInstance();
        try {
            normal = loader.loadImage(nomarlimage);
            highlighted = loader.loadImage(highlightedimage);
        } catch (IOException ex) {
        }
       
    }
    public void setPos(int x, int y){
        this.posX = x;
        this.posY = y;
    }
    
     public void pointerPressed(int x, int y) {
        if(isPressed(x, y)) {
            ishighlighted = true;
        }else {
            ishighlighted = false;
        }
    }
    public void pointerReleased(int x, int y) {
        ishighlighted = false;
        if(isPressed(x, y))
            setMenuItem();
    }
     public final boolean isPressed(int x, int y) {
        return getArea().isPointInside(x, y);
    }
     private final Rectangle getArea() {
        return new Rectangle(posX, posY, normal.getWidth(), normal.getHeight());
    }
      public void setActive() {
        ishighlighted = true;
    }
    public void setInactive() {
        ishighlighted = false;
    }
    public void render(Graphics g) {
        int anchor = Graphics.TOP|Graphics.LEFT;
        if(ishighlighted) {
            g.drawImage(highlighted, posX, posY, anchor);
        }else {
            g.drawImage(normal, posX, posY, anchor);
        }
    }
}
